package com.hunter.api.mapper;

import java.util.List;

import com.hunter.api.bean.TokenBean;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * @author HunterHuang
 * @version 1.0
 * @ClassName TokenMapper
 * @date 2019/5/30 10:12
 */
@Repository
public interface TokenMapper {
    @Select("SELECT * FROM app.log_token ")
    @Results()
    List<TokenBean> getAll();

    @Select("SELECT * FROM app.log_token WHERE user_id = #{user_id} and token  = #{token} limit 1")
    @Results()
    TokenBean cheakToecn(TokenBean token);


    @Insert("INSERT INTO app.log_token(user_id,token,duration,expires_time) VALUES(#{user_id},#{token},#{duration},#{expires_time})")
    void insert(TokenBean tokenBean);

    @Update("UPDATE app.log_token " +
            "SET user_id=#{user_id},token=#{token},duration=#{duration},expires_time = #{expires_time} WHERE id =#{id}")
    void update(TokenBean tokenBean);

}
